$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/barticleshield/getList',
        datatype: "json",
        colModel: [
            { label: '文章ID', name: 'articleId', index: 'article_id',align: "center", width: 50,},
            { label: '文章名称', name: 'articleTitle', index: 'article_title', align: "center", width: 80},
            { label: '屏蔽时间', name: 'createTime', index: 'create_time',align: "center", width: 80 },
            { label: '操作', name: '', index: '',align: "center", width: 80 ,formatter:function(value,options,rowData){
                    var articleId=rowData["articleId"];
                    return "<a class='btn btn-danger' onclick='vm.delete("+articleId+")'>删除</a>";
                }
            },
        ],
        viewrecords: true,
        height: "100%",
        rowNum: 15,
        rowList : [15,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        postData:{'articleId': vm.q.articleId},
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            articleId: null
        },
        showList: true,
    },
    methods: {
        query: function () {
            vm.reload(1);
        },
        delete: function (articleId) {
            if (!articleId) {
                alert("文章不存在");
                return;
            }

            layer.confirm("您确定删除吗？", function (index) {
                $.ajax({
                    type: "POST",
                    url: baseURL + 'sys/barticleshield/deleteByArticleId/' + articleId,
                    contentType: "application/json",
                    success: function(r){
                        if(r.code==0){
                            layer.close(index);
                            vm.reload(1);
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            })
        },
        reload: function (page) {
            debugger;
            vm.showList = true;
            if (!page) {
                page = $("#jqGrid").jqGrid('getGridParam','page');
            }
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'articleId': vm.q.articleId},
                page:page
            }).trigger("reloadGrid");
        },
    }
});